package com.agua.enturno.vista.componentes;

import org.apache.wicket.ajax.IAjaxCallDecorator;
import org.apache.wicket.ajax.calldecorator.AjaxPreprocessingCallDecorator;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

public abstract class AjaxConfirmLink extends AjaxLink<String> {

	private static final long serialVersionUID = 1L;
	
	public AjaxConfirmLink(String id, String confirmationMessage) {
		this(id, new Model<String>(confirmationMessage));
	}
	
	public AjaxConfirmLink(String id, IModel<String> model) {
		super(id, model);
	}

	@Override
	protected IAjaxCallDecorator getAjaxCallDecorator() {
		return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {
			private static final long serialVersionUID = 1L;

			@Override
			public CharSequence preDecorateScript(CharSequence script) {
				return "if(!confirm('" + getModelObject() + "')) return false;" + script;
			}
		};
	}
	
}
